var status_code = function (code) {
  //权限
  switch (code) {
    case 10002:
      return "你没有该操作权限";
      break;
    case 10000:
      return "你的账户已过期，或在异地登录，请重新登陆";
      break;
    default:
      return true
  }
};
var dataSuccess = function (val, this_) {
  //成功的返回
  switch (val.status_code) {
    case 200:
      this_.$notify({
        title: '成功',
        message: val.Massage,
        type: 'success'
      });
      break;
    case 2:
      // console.log(123);
      break;
  }
};
var formattime = function (time) {
  //设置时间
  let endTime = new Date(time);
  var hour = endTime.getHours() < 10 ? "0" + endTime.getHours() : endTime.getHours();
  var minute = endTime.getMinutes() < 10 ? "0" + endTime.getMinutes() : endTime.getMinutes();
  var second = endTime.getSeconds() < 10 ? "0" + endTime.getSeconds() : endTime.getSeconds();
  return `${endTime.getFullYear()}年${endTime.getMonth() + 1}月${endTime.getDate()}日:${hour}时-${minute}分-${second}秒`
};
var getStorage = function (k, v) {
  //添加 localStorage
  window.localStorage.setItem(k, v);
};
var setStorage = function (k) {
  //读取 localStorage
  return window.localStorage.getItem(k);
};
var Ed = function (val, this_) {
  //分返错误
  this_.$notify.error({
    title: '错误',
    message: val.response.data.Massage
  });
}.bind(this);
var exportexcel = function (herder, value, dataval, text) {
  //表格下载
  const {export_json_to_excel} = require('../vendor/Export2Excel');
  require.ensure([], () => {
    const tHeader = herder;
    const filterVal = value;
    const list = dataval;
    const data = this.formatJson(filterVal, list);
    export_json_to_excel(tHeader, data, text);
  })
};

var formatJson = function (filterVal, jsonData) {
  return jsonData.map(v => filterVal.map(j => v[j]))
};
var userphone_test = function (val, this_) {

  var reg = /^[1-9]\d*$|^0$/;
  if (reg.test(val) == true) {
    if (val.length == 11) {
      return true;
    } else {
      this_.$notify.error({
        title: '错误',
        message: '您输入的电话号码长度不正确'
      });
    }
  } else {
    this_.$notify.error({
      title: '错误',
      message: '您输入的格式不正确！'
    });
  }
}
//电话号码搜索


var user_type = function (type) {
  //角色过滤
  switch (type) {
    case 1:
      return "管理员";
      break;
    case 2:
      return "员工";
      break;
    case 3:
      return "一级代理商";
      break;
    case 4:
      return "二级代理商";
      break;
    case 5:
      return "用户";
      break;
  }
};


export default{
  status_code,
  dataSuccess,
  formattime,
  getStorage,
  setStorage,
  exportexcel,
  formatJson,
  Ed,
  user_type,
  userphone_test
};
